/*
 * @Description: 生成Mapper
 * @Author: DHL
 * @Date: 2022-01-30 14:20:12
 * @LastEditors: DHL
 * @LastEditTime: 2022-07-18 08:41:37
 */

import { firstToUpperCase, firstToLowerCase } from '../../../utils/codeGenUtils'

export function createApi(codeGenConfig: any) {
  const classNameFirstToUpperCase = firstToUpperCase(codeGenConfig.className)
  const classNameFirstToLowerCase = firstToLowerCase(codeGenConfig.className)

  return `
/*
 * @Description: ${codeGenConfig.genName} - 接口
 * @Author: ${codeGenConfig.genAuthor}
 * @Date: ${codeGenConfig.createData}
 * @LastEditors: ${codeGenConfig.genAuthor}
 * @LastEditTime: ${codeGenConfig.createData}
 */

import { $get, $post, $put, $exportExcel } from '/@/utils/http'
import { ContentTypeEnum } from '/@/constant/http'
import {
  ${classNameFirstToUpperCase}Model,
  ${classNameFirstToUpperCase}Params,
  ${classNameFirstToUpperCase}PageParams,
  ${classNameFirstToUpperCase}PageResultModel,
  ${classNameFirstToUpperCase}ResultModel
} from './model/${classNameFirstToLowerCase}Model'

/**
 * 分页查询
 */
export const api${classNameFirstToUpperCase}Search = (searchParams: ${classNameFirstToUpperCase}PageParams) =>
  $get<${classNameFirstToUpperCase}PageResultModel>({
    url: '/${classNameFirstToLowerCase}/search',
    params: searchParams
  })

/**
 * 根据ID获取详情
 */
export const api${classNameFirstToUpperCase}GetById = (id: string) =>
  $get<${classNameFirstToUpperCase}ResultModel>({
    url: '/${classNameFirstToLowerCase}/getById',
    params: { id: id }
  })

/**
 * 保存信息
 */
export const api${classNameFirstToUpperCase}Save = (saveParams: ${classNameFirstToUpperCase}Model) =>
  $post<${classNameFirstToUpperCase}ResultModel>({
    url: '/${classNameFirstToLowerCase}/save',
    contentType: ContentTypeEnum.json,
    params: saveParams
  })

/**
 * 更新信息
 */
export const api${classNameFirstToUpperCase}UpdateById = (updateParams: ${classNameFirstToUpperCase}Model) =>
  $put<${classNameFirstToUpperCase}ResultModel>({
    url: '/${classNameFirstToLowerCase}/updateById',
    contentType: ContentTypeEnum.json,
    params: updateParams
  })

/**
 * 批量删除信息
 */
export const api${classNameFirstToUpperCase}BatchDeleteByIds = (ids: string) =>
  $post<${classNameFirstToUpperCase}ResultModel>({
    url: '/${classNameFirstToLowerCase}/batchDeleteByIds',
    params: { ids: ids }
  })

/**
 * 批量逻辑删除
 */
export const api${classNameFirstToUpperCase}LogicBatchDeleteByIds = (ids: string) =>
  $post<${classNameFirstToUpperCase}ResultModel>({
    url: '/${classNameFirstToLowerCase}/logicBatchDeleteByIds',
    params: { ids: ids }
  })

/**
 * 导出
 */
 export const api${classNameFirstToUpperCase}Export = (searchParams: ${classNameFirstToUpperCase}Params, fileName: string) =>
  $exportExcel<${classNameFirstToUpperCase}ResultModel>(
    {
      url: '/${classNameFirstToLowerCase}/exportExcel',
      params: searchParams
    },
    fileName
  )
`
}
